package ase.assignment.sts.rmi.server;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.Naming;

import ase.assignment.sts.api.CustomerHandler;
import ase.assignment.sts.api.HandlerFactory;
import ase.assignment.sts.api.PortfolioHandler;
import ase.assignment.sts.api.StockHandler;
import java.rmi.NotBoundException; 
import java.net.MalformedURLException;

import ase.assignment.sts.utils.STSConstants;

public class HandlerFactoryRMIServerImpl extends UnicastRemoteObject implements
		HandlerFactory {
	private static final long serialVersionUID = 5981817298726766254L;

	public HandlerFactoryRMIServerImpl() throws RemoteException {
		super();
	}

	public CustomerHandler getCustomerHandler() throws RemoteException {
		System.out.println("...........................");
		
		try{
			
			CustomerHandlerRMIServerImpl ch = (CustomerHandlerRMIServerImpl)Naming.lookup("rmi://172.24.13.245/" + STSConstants.RMI_NAME_CUSTOMER);
			return ch;	
		}catch(NotBoundException nbe ){
			System.out.println("NotBoundException");
			System.out.println(nbe);
		}catch (MalformedURLException murle) { 
            System.out.println(); 
            System.out.println(
              "MalformedURLException"); 
            System.out.println(murle); 
        } 
        
        return null;
		
	}

	public PortfolioHandler getPortfolioHandler() throws RemoteException {
		return new PortfolioHandlerRMIServerImpl();
	}

	public StockHandler getStockHandler() throws RemoteException {
		return new StockHandlerRMIServerImpl();
	}

	public boolean isActive() throws RemoteException {
		// TODO Auto-generated method stub
		return false;
	}

}
